﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using YFIN.View.Helper;
using YFIN.View.MessageServiceRef;
using YFIN.View.ViewModels;
using System.Windows.Threading;

namespace YFIN.View.User
{
    public partial class Message : UserControl
    {
        public static MessageVM Mvm { get; set; }
        public Message()
        {
            InitializeComponent();
            Mvm = new MessageVM();
            DataContext = Mvm;
           
        }
        
        private void edit_Click(object sender, RoutedEventArgs e)
        {
            Mvm.ShowDetail(((Button)sender).DataContext);
        }

        private void delete_Click(object sender, RoutedEventArgs e)
        {
            Mvm.CurrentMessage = ((Button)sender).DataContext as ModelMessage;
            Mvm.Delete();
        }

        private void cbRowDetailsVis_SelectionChanged(object sender, RoutedEventArgs e)
        {
            ComboBox cb = sender as ComboBox;
            ComboBoxItem cbi = cb.SelectedItem as ComboBoxItem;
            if (this.MainDataGrid != null)
            {
                if (cbi.Content.ToString() == "Selected Row (Default)")
                    MainDataGrid.RowDetailsVisibilityMode = DataGridRowDetailsVisibilityMode.VisibleWhenSelected;
                else if (cbi.Content.ToString() == "None")
                    MainDataGrid.RowDetailsVisibilityMode = DataGridRowDetailsVisibilityMode.Collapsed;
                else if (cbi.Content.ToString() == "All")
                    MainDataGrid.RowDetailsVisibilityMode = DataGridRowDetailsVisibilityMode.Visible;
            }
        }
        // Freeze the row details if the check box is checked.
        private void cbFreezeRowDetails_Changed(object sender, RoutedEventArgs e)
        {
            CheckBox cb = sender as CheckBox;
            if (this.MainDataGrid != null)
                this.MainDataGrid.AreRowDetailsFrozen = (bool)cb.IsChecked;
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            Stage.ResetNewMsg();
        }
    }
}
